<template>
	<el-container>
        <el-container>
            <el-header>
                <div class="right-panel">
                    <el-input v-model="search.keywords" placeholder="请输入关键词" clearable @change="upsearch"></el-input>
                    <el-date-picker v-model="search.time_range" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="报警开始时间" end-placeholder="报警结束时间" :size="size"/>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch">查询</el-button>
                </div>
            </el-header>
            <el-header>
                <el-button type="primary" icon="el-icon-plus" @click="add" v-auth="'mainProject.add'">新增报警项目</el-button>
            </el-header>
            <el-main class="nopadding">
                <scTable ref="table" tableName="alarmColumn" :apiObj="apiObj" :column="column" row-key="id" stripe :params="query" remoteSort remoteFilter border >
                    <el-table-column fixed type="selection" width="50"></el-table-column>
                    <el-table-column fixed type="index" label="序号" align="center" width="50"></el-table-column>
                    <template #FSTATUS="{row}">
                        <div v-if="row.FSTATUS==0">未处理</div>
                        <div v-if="row.FSTATUS==2">已处理</div>
                        <div v-if="row.FSTATUS==3">已报修</div>
                        <div v-if="row.FSTATUS==1">误报</div>
                    </template>
                    <el-table-column label="操作" align="center" width="150" fixed="right">
                        <template #default="scope">
                            <el-button-group>
                                <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-auth="'mainProject.edit'">修改</el-button>
                                <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                                    <template #reference>
                                        <el-button text type="danger" size="small" v-auth="'mainProject.delete'">删除</el-button>
                                    </template>
                                </el-popconfirm>
                                <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)" :disabled="scope.row.FSTATUS>0">处理</el-button>
                                <el-button text type="primary" size="small" @click="table_repair(scope.row, scope.$index)" :disabled="scope.row.FSTATUS>0  ">报修</el-button>
                            </el-button-group>
                        </template>
                    </el-table-column>
                </scTable>
                <!-- <scTable ref="table" :apiObj="apiObj" @selection-change="selectionChange" stripe remoteSort remoteFilter border>
                    <el-table-column type="selection"  align="center" width="50"></el-table-column>
                    <el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
                    <el-table-column label="报警单据编号" prop="FBILLLNO" align="center"></el-table-column>
                    <el-table-column label="设备内码" prop="FEQUID" align="center"></el-table-column>
                    <el-table-column label="设备名称" prop="FEQUNAME" align="center"></el-table-column>
                    <el-table-column label="报警开始时间" prop="FBEGINDATE" align="center"></el-table-column>
                    <el-table-column label="报警结束时间" prop="FENDDATE" align="center"></el-table-column>
                    <el-table-column label="报警持续时间" prop="FLONGDURRATION" align="center"></el-table-column>
                    <el-table-column label="单据状态" prop="FSTATUS" align="center">
                        <template #default="{row}">
                            <div v-if="row.FSTATUS==0">未处理</div>
                            <div v-if="row.FSTATUS==2">已处理</div>
                            <div v-if="row.FSTATUS==3">已报修</div>
                            <div v-if="row.FSTATUS==1">误报</div>
                        </template>
                    </el-table-column>
                    <el-table-column label="报警触发类型" prop="FCOMBLIST" align="center"></el-table-column>
                    <el-table-column label="触发器名称" prop="FALARMDES" align="center"></el-table-column>
                    <el-table-column label="触发条件" prop="FALARMCONDITION" align="center"></el-table-column>
                    <el-table-column label="操作" align="center" width="150">
                        <template #default="scope">
                            <el-button-group>
                                <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-auth="'mainProject.edit'">修改</el-button>
                                <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                                    <template #reference>
                                        <el-button text type="danger" size="small" v-auth="'mainProject.delete'">删除</el-button>
                                    </template>
                                </el-popconfirm>
                                <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)" :disabled="scope.row.FSTATUS>0">处理</el-button>
                                <el-button text type="primary" size="small" @click="table_repair(scope.row, scope.$index)" :disabled="scope.row.FSTATUS>0  ">报修</el-button>
                            </el-button-group>
                        </template>
                    </el-table-column>
                </scTable> -->
            </el-main>
        </el-container>
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false" draggable></save-dialog>
    <handle v-if="dialog.hand" ref="handDialog" @success="handleSuccess" @closed="dialog.hand = false" draggable></handle>
    <save v-if="dialog.rep" ref="repDialog" @success="handleSuccessss" @closed="dialog.rep = false" draggable></save>
	</el-container>
</template>

<script>
import Handle from "@/views/jiankong/device/handle.vue";
import saveDialog from './save.vue'
import save from '@/views/device/weixiu/fault/save.vue'
export default {
	name: 'user',
	components: {
		saveDialog,
        Handle,
        save,
	},
	data() {
		return {
			dialog: {
				save: false,
                rep: false,
                hand: false,
			},
			groupFilterText: '',
			group: [],
			apiObj: this.$API.jiankong.monitorMonitor.lists,
			selection: [],
			search: {
				title: null,
				time_range: null,
			},
			//所需数据选项
			cates: [],
            data:[
                {id:0,name:'ceshi'},
                {id:1,name:'ceshi'},
            ],
            column:[
                {label: "报警单据编号",prop: "FBILLLNO",width: "150"},
                {label: "设备内码",prop: "FEQUID",width: "150"},
                {label: "设备名称",prop: "FEQUNAME",width: "150"},
                {label: "报警开始时间",prop: "FBEGINDATE",width: "150"},
                {label: "报警结束时间",prop: "FENDDATE",width: "150"},
                {label: "报警持续时间",prop: "FLONGDURRATION",width: "150"},
                {label: "单据状态",prop: "FSTATUS",width: "150"},
                {label: "报警触发类型",prop: "FCOMBLIST",width: "150"},
                {label: "触发器名称",prop: "FALARMDES",width: "150"},
                {label: "触发条件",prop: "FALARMCONDITION",width: "150"},
            ],
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.group.filter(val);
		}
	},
	mounted() {
	},
	methods: {
		//添加
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
		},
        table_detail(row){
            this.$router.push({
			path: '/device/list/detail',
            query:{
                id:row.id
            }
		})
        },
		//编辑
		table_edit(row) {
            console.log('row :>> ', row);
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
        // 处理
        table_show(row){
            this.dialog.hand = true;
            this.$nextTick(() => {
                this.$refs.handDialog.open("edit").setData(row);
            });
        },
        // 报修
        table_repair(row){
            // 列表加上设备code,class_title,设备id
            let obj = {
                id:row.device_id,
                code:row.FEQUID,
                title:row.FEQUNAME,
                class_title:row.class_title,
                listId:row.id
            }
            this.dialog.rep = true;
            this.$nextTick(() => {
                this.$refs.repDialog.open("add").setId(obj);
            });
        },
        goLocation(){
            this.$router.push({
                path: 'storeroomLocation',
            })
        },
		//删除
		async table_del(row, index) {
			var reqData = { id: row.id }
			var res = await this.$API.jiankong.monitorMonitor.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
                this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
            console.log('this.search.time_range :>> ', this.search.time_range);
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
            this.printArr = ''
		},
        selectionChange(selection) {
			this.selection = selection;
		},
        async handleSuccessss(data,mode,listId){
            console.log('mode :>> ', mode);
            var res = await this.$API.jiankong.monitorMonitor.update_status.post({FSTATUS:3,id:listId});
            console.log('res :>> ', res);
            this.$refs.table.refresh()
        },
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}
.shopInfo{
    display: flex;
    align-items: center;
}
.img{
    width: 100px;
    height: 100px;
    margin-right: 5px;
}
</style>
